<template>
    <div style="padding:20px">
        <div style="display: flex;justify-content: space-between;align-items: center">
            <h1 class="title">角色列表</h1>
            <el-button type="primary" @click="drawerVisible = true"><el-icon>
                    <Plus />
                </el-icon>创建角色</el-button>
        </div>
        <div>

            <el-table :data="roleAgentList">
                <template #empty>
                    <el-empty description="暂无角色，快去创建吧~" />
                </template>
                <el-table-column prop="id" label="ID" />
                <el-table-column prop="name" label="角色名称" />
                <el-table-column prop="character_id" label="角色ID" />
                <el-table-column prop="introduction" label="角色说明" />
                <el-table-column prop="create_time" label="创建时间" />
                <!-- <el-table-column prop="count" label="知识数量" /> -->
                <el-table-column fixed="right" label="操作" min-width="120">
                    <template #default="scope">
                        <el-button link type="primary" size="small"
                            @click="() => { this.$router.push(`/roleAgentInfo/${scope.row.id}`) }">
                            详情
                        </el-button>
                        <el-button link type="primary" size="small"
                            @click="deleteRoleAgent(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>

    <el-drawer v-model="drawerVisible" title="新增角色" :direction="direction" :before-close="handleClose">

        <el-form label-position="top">
            <el-form-item label="角色名称">
                <el-input placeholder="请输入角色名称。美髯公关云长" v-model="form.name" />
            </el-form-item>
            <el-form-item label="角色介绍">
                <el-input placeholder="请输入角色介绍。满腔忠义的关云长" v-model="form.introduction" />
            </el-form-item>
            <el-form-item label="角色Prompt">
                <el-input placeholder="请输入角色Prompt。我们来玩一个角色扮演的游戏， 你是「满腔忠义的关云长」。" v-model="form.basic_information" />
            </el-form-item>
            <el-form-item label="开场白">
                <el-input placeholder="请输入角色开场白。我是「关云长」，很高心与你玩游戏" v-model="form.opening_line" />
            </el-form-item>
            <el-form-item label="特殊要求">
                <el-input placeholder="请输入角色特殊要求。请在对话时尽可能的展现你的性格、感情， 用文言文回答， 并使用古人的语气和用词。" v-model="form.traits" />
            </el-form-item>
            <el-form-item label="任务目标">
                <el-input placeholder="请输入角色任务目标。我要关羽拜把子。" v-model="form.chat_objective" />
            </el-form-item>
            <el-form-item label="角色音色">
                <el-select placeholder="请选择角色音色。" v-model="form.sound">
                    <el-option label="女孩" value="女孩" />
                </el-select>
            </el-form-item>
        </el-form>

        <template #footer>
            <div style="flex: auto">
                <el-button @click="drawerVisible = false">取消</el-button>
                <el-button type="primary" @click="createRoleAgent">确认</el-button>
            </div>
        </template>
    </el-drawer>
</template>
<script>
import { fa } from 'element-plus/es/locale/index.mjs';
import { POST } from '../../util/axios.js'
export default {
    data() {
        return {
            roleAgentList: [],
            drawerVisible: false,
            form: { basic_information: "", name: "", introduction: "", opening_line: "", traits: "", chat_objective: '', sound: "女孩", id: 0 },
        }
    },
    methods: {
        async getRoleAgentList() {
            let rs = await POST("/roleAgent/getRoleAgentList", "POST", {}, false)
            console.log("rs:>>:", rs)
            this.roleAgentList = rs.data
        },
        async createRoleAgent() {
            let rs = await POST("/roleAgent/createRoleAgent", "POST", this.form, true)
            console.log("rs:>>:", rs)
            this.drawerVisible = false
            this.getRoleAgentList()
            // this.roleAgentList = rs.data
        },
        async deleteRoleAgent(row) {

            let rs = await POST("/roleAgent/deleteRoleAgent", "POST", row, true)
            console.log("rs:>>:", rs)
            this.getRoleAgentList()


        }
    },
    mounted() {
        this.getRoleAgentList()
    }
}
</script>
<style></style>